﻿using System;
using System.Linq.Expressions;

namespace SmartLib.Extensions
{
	/// <summary>
	/// 
	/// </summary>
	public static class LambdaExpressionExtensions
	{
		/// <summary>
		/// Gets the name of the member.
		/// </summary>
		/// <param name="expression">The expression.</param>
		/// <returns></returns>
		public static string GetMemberName(this LambdaExpression expression)
		{
			var memberExpression = expression.Body as MemberExpression;
			if (memberExpression == null) throw new InvalidOperationException();
			return memberExpression.Member.Name;
		}
	}
}
